package com.vpen.server.codec;

import com.vpen.server.dto.FileMessage;
import com.vpen.server.dto.Message;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2024/4/4 23:01
 */
@Slf4j
public class CommandDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        log.debug("CommandDecoder before");
        log.debug("编码:CommandDecoder:{}", Integer.toHexString(in.readByte()));
        out.add(new Message().setHex(ByteBufUtil.hexDump(in)));
        if (in.isReadable()){
            int readableBytes = in.readableBytes();
            in.skipBytes(readableBytes);
            log.debug("跳过{}字节",readableBytes);
        }
        log.debug("CommandDecoder after");
    }
}
